/*

Interval Trainer , a tool for your android phone helping with your excercise  
Copyright (C) 2009  Henrik Andersson

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

package se.dinamic.android.intervaltrainer;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.preference.PreferenceManager;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;


public class IntervalTrainerActivity extends Activity
{
    private final static int ACTIVITY_ABOUT               		        	= 0;
    private final static int ACTIVITY_SETTINGS          			        = 1;
    private final static int ACTIVITY_CREATE_TASK_WIZARD        	= 2;
    private final static int ACTIVITY_QUICK_TASK_WIZARD         	= 3;
    
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // Show about dialog if this is the first time we run the app
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        if( sp.getBoolean("show_about",true) ) {
            SharedPreferences.Editor editor = sp.edit();
            editor.putBoolean("show_about",false);
            editor.commit();
            startActivity( new Intent( IntervalTrainerActivity.this, IntervalTrainerAboutActivity.class ) );
        }
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, ACTIVITY_CREATE_TASK_WIZARD, 0, getResources( ).getString( R.string.new_exercise ) );
        menu.add(0, ACTIVITY_SETTINGS, 0, getResources( ).getString( R.string.settings ) );
        menu.add(0, ACTIVITY_ABOUT, 0, getResources( ).getString( R.string.about ) );
        return true;
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if( resultCode == RESULT_OK ) {         // Only process if activity is successfully finished
            switch( requestCode ) {
                case ACTIVITY_CREATE_TASK_WIZARD: {
                    // Data holds an JSONObject with the new defined exercise configuration...
                    
                } break;
                
                default: {
                    Log.v( "IntervalTrainerActivity","onActivityResult(): Unhandled request " + requestCode );
                } break;
            }
        } 
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case ACTIVITY_SETTINGS:
                startActivity( new Intent( IntervalTrainerActivity.this, IntervalTrainerSettings.class ) );
            return true;
            
            case ACTIVITY_ABOUT:
                startActivity( new Intent( IntervalTrainerActivity.this, IntervalTrainerAboutActivity.class ) );
            return true;
            
            case ACTIVITY_CREATE_TASK_WIZARD:
                startActivityForResult( new Intent( IntervalTrainerActivity.this, CreateTaskWizardActivity.class ), ACTIVITY_CREATE_TASK_WIZARD );
            return true;
            
            case ACTIVITY_QUICK_TASK_WIZARD:
               // startActivity( new Intent( IntervalTrainerActivity.this, CreateQuickTaskActivity.class ) );
            return true;
        }
        return false;
    }
}
